package cn.com.bluemoon.daps.sync.vo.applypublish;

import cn.com.bluemoon.daps.common.domain.UserPermissionApi;
import cn.com.bluemoon.daps.sync.base.ApplyPassGroup;
import cn.com.bluemoon.daps.sync.base.ApplyRevertGroup;
import cn.com.bluemoon.daps.sync.base.ApplyUnPassGroup;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;

/**
 * 申请发布确认后
 *
 * @author Jarod.Kong
 * @date 2021/7/2 15:53
 */
@Builder
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ApplyPublishParam implements UserPermissionApi<String> {

    @ApiModelProperty(value = "申请发布的模型id")
    @NotEmpty(message = "模型id不可为空", groups = {ApplyPassGroup.class, ApplyRevertGroup.class, ApplyUnPassGroup.class})
    private String modelId;

    /**
     * {@link cn.com.bluemoon.daps.sync.entity.DapSyncProdEnvTask#COMPARE_VERSION_KEY}对应的值
     */
    @ApiModelProperty(value = "来源同步接口提供的对比结果版本号对应'DapSyncProdEnvTask#Id'")
    @NotEmpty(message = "对比结果版本号不可为空", groups = {ApplyPassGroup.class, ApplyRevertGroup.class, ApplyUnPassGroup.class})
    private String compareVersion;

    @ApiModelProperty(value = "申请发布中的变更单号")
    @NotEmpty(message = "变更单号不可为空", groups = {ApplyPassGroup.class, ApplyRevertGroup.class, ApplyUnPassGroup.class})
    private String changeOrder;

    @ApiModelProperty(value = "申请发布的申请人")
    @NotEmpty(message = "申请发布的申请人不可为空", groups = {ApplyPassGroup.class, ApplyRevertGroup.class, ApplyUnPassGroup.class})
    private String applicationBy;

    @ApiModelProperty(value = "申请发布的申请时间", example = "1970-01-01 00:00:00")
    @JsonFormat(
            pattern = "yyyy-MM-dd HH:mm:ss",
            timezone = "GMT+8"
    )
    @NotNull(message = "申请发布的申请时间不可为空", groups = {ApplyPassGroup.class, ApplyRevertGroup.class, ApplyUnPassGroup.class})
    private LocalDateTime applicationTime;

    @ApiModelProperty(value = "申请发布通过的审核人")
    @NotEmpty(message = "申请发布通过的审核人不可为空", groups = {ApplyPassGroup.class})
    private String verifyBy;

    @ApiModelProperty(value = "申请发布的变更描述")
    @NotEmpty(message = "申请发布的变更描述不可为空", groups = {ApplyPassGroup.class})
    private String changeDesc;

    @ApiModelProperty(value = "人工审核还是自动审核通过，true: 为自动审核，false为人工审核", example = "false")
    private Boolean autoPass;

    /**
     * @return 获取mvc传输中对应模型的id
     */
    @Override
    public String getUserPermissionKeyValue() {
        return this.modelId;
    }

    /**
     * 定义自动通过描述
     * @return str
     */
    public String getAutoPassDesc() {
        return Boolean.TRUE.equals(autoPass) ? "自动审核" : "人工审核";
    }
}